package com.douqu.game.core.entity;

import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.SendUtils;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2017-11-20 10:28
 */
public class ChangeGoods extends EntityObject {

    private List<SGCommonProto.FlushData> showList;

    private List<SGCommonProto.FlushData> otherList;

    private List<String> notices;

    private Map<Integer, Integer> legionChainCacheMap;

    /**
     * 红点的缓存，不需要写入数据库
     */
    private List<SGCommonProto.E_RED_POINT_TYPE> redPointTypes;

    /**
     * 序列号
     */
    private int index;

    public ChangeGoods()
    {
        showList = new CopyOnWriteArrayList<>();
        otherList = new CopyOnWriteArrayList<>();
        redPointTypes = new CopyOnWriteArrayList<>();
        notices = new CopyOnWriteArrayList<>();
        legionChainCacheMap = new ConcurrentHashMap<>();
    }


    public void addGoods(SGCommonProto.E_GOODS_TYPE goodsType, int id, int change, int curValue, String uniqueId, long endTime, Object... hide)
    {
        if((hide != null && hide.length > 0) || change < 0)
            otherList.add(SendUtils.createFlushData(goodsType, id, change, curValue, uniqueId, endTime, ++index));
        else
            showList.add(SendUtils.createFlushData(goodsType, id, change, curValue, uniqueId, endTime, ++index));
    }

    public List<SGCommonProto.FlushData> getChangeGoodsList()
    {
        List<SGCommonProto.FlushData> list = new CopyOnWriteArrayList<>();
        list.addAll(showList);
        list.addAll(otherList);
        return list;
    }


//    public void addShowGoods(SGCommonProto.E_GOODS_TYPE goodsType, int id, int change, int curValue)
//    {
//        if(change <= 0)
//            return;
//
//        showGoodsGetList.add(SendUtils.createGoodsGet(goodsType, id, change, curValue));
//    }



//    public List<SGCommonProto.FlushData> getFlushDataList()
//    {
//        return flushDataList;
//    }

    public List<SGCommonProto.FlushData> getShowList() {
        return showList;
    }

    public List<SGCommonProto.FlushData> getOtherList() {
        return otherList;
    }

    public List<SGCommonProto.E_RED_POINT_TYPE> getRedPointTypes() {
        return redPointTypes;
    }

    public List<String> getNotices() {
        return notices;
    }

    public void clearGoodsList()
    {
        showList.clear();
        otherList.clear();
    }

    public Map<Integer, Integer> getLegionChainCacheMap() {
        return legionChainCacheMap;
    }

    public void clearNoticeList()
    {
       notices.clear();
    }
}

